package com.Test.Alipay_story;

public class Alipay {

  private Accunt[] accunts = new Accunt[5];
  private String[] ids = new String[5];
  private String[] pwds = new String[5];

  public Alipay() {
    this.accunts[0] = new Accunt("1000", "100", 0);
    this.accunts[1] = new Accunt("1001", "101", 1000);
    this.accunts[2] = new Accunt("1002", "102", 2000);
    this.accunts[3] = new Accunt("1003", "103", 3000);
    this.accunts[4] = new Accunt("1004", "104", 4000);
    int i = 0;
    for (Accunt a : this.accunts) {
      ids[i] = a.Id;
      pwds[i] = a.password;
    }
  }

  public String AliTransServer(String fromId, String pwd, String toID, int money) {
    for (int i = 0; i < accunts.length; i++) {
      //
      if (accunts[i].Id.equals(fromId)) {
        if (accunts[i].password.equals(pwd)) {
          if (accunts[i].overage > money) {
            accunts[i].overage -= money;
          } else {
            return "余额不足";
          }
        } else {
          return "密码错误";
        }
      }
      }return "转账失败，账号不存在；";

    }
  }

